{block name="main"}

        <div class="mb-20">
            <a href="{:__URL('ADDONS_MAINaddSecKill')}" class="btn btn-primary"><i class="icon icon-add1"></i> 添加秒杀商品</a>
        </div>
        <table class="table v-table table-auto-center">
            <thead>
            <tr>
                <th>场次</th>
                <th>进行中商品</th>
                <th>明日秒杀商品</th>
                <th>待审核商品</th>
                <th class="col-md-2 pr-14 operationLeft">操作</th>
            </tr>
            </thead>
            <tbody id="seckill_list">
            </tbody>
        </table>
        <input type="hidden" id="page_index">
        <nav aria-label="Page navigation" class="clearfix">
            <ul id="page" class="pagination pull-right"></ul>
        </nav>

        <!-- page end -->

{/block}
{block name="script"}
<script id="shop_curr_list" type="text/html">
    <%each data as item index%>
    <tr>
        <td>
            <%item.seckill_name%>点场
            <input type="hidden" name="seckill_name" value="<%item.seckill_name%>">
        </td>
        <%if item.today_total == null %>
            <td>0件</td>
        <%else%>
            <td><%item.today_total%>件</td>
        <%/if%>
        <%if item.tomorrow_total == null %>
            <td>0件</td>
        <%else%>
            <td><%item.tomorrow_total%>件</td>
        <%/if%>
        <%if item.uncheck_total == null %>
            <td>0件</td>
        <%else%>
            <td><%item.uncheck_total%>件</td>
        <%/if%>
        <td class="fs-0 operationLeft">
            <a href="javascript:;" class="btn-operation" data-seckill_id="<%item.seckill_id%>" data-condition="today">进行中</a>
            <a href="javascript:;" class="btn-operation" data-condition="unchecked">待审核</a>
            <a href="javascript:;" class="btn-operation" data-condition="checked">已审核</a>
        </td>
    </tr>
    <%/each%>
</script>

<script>
    require(['util', 'tpl'], function (util, tpl) {
        util.initPage(LoadingInfo);
        tpl.helper("timeStamp", function (timeStamp) {
            if (timeStamp > 0) {
                var date = new Date();
                date.setTime(timeStamp * 1000);
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? ('0' + m) : m;
                var d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                var h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                var minute = date.getMinutes();
                var second = date.getSeconds();
                minute = minute < 10 ? ('0' + minute) : minute;
                second = second < 10 ? ('0' + second) : second;
                return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
            } else {
                return "";
            }
        });

        $('#seckill_list').on('click', '.btn-operation', function () {
            var type = $(this).attr('data-condition');
            //获取当前时间段
            var seckill_name = $(this).parent().parent().find('input[name=seckill_name]').val();
            switch (type) {
                case 'today':
                    location.href = __URL('ADDONS_MAINtodaySeckillList&seckill_name=' + seckill_name + '&act=today');
                    break;
                case 'unchecked':
                    location.href = __URL('ADDONS_MAINuncheckSeckillList&seckill_name=' + seckill_name + '&act=unchecked');
                    break;
                case 'checked':
                    location.href = __URL('ADDONS_MAINcheckedSeckillList&seckill_name=' + seckill_name + '&act=checked');
                    break;
            }
        })

        function LoadingInfo(page_index) {
            // console.dir(123123123);return;
            $("#page_index").val(page_index);
            $.ajax({
                type: "post",
                url: "{$secKillListUrl}",
                data: {
                    "page_index": page_index,
                    // "search_text": $("#search_text").val(),
                    'website_id': '{$website_id}',
                    'instance_id': '{$instance_id}'
                },
                success: function (data) {
                    html ='';
                    html += '<tr><td class="h-200" colspan="5">暂无符合条件的数据记录</td></tr>';
                    if(tpl('shop_curr_list', data)){
                        $("#seckill_list").html(tpl('shop_curr_list', data));
                    }else{
                        $("#seckill_list").html(html);
                    }
                    $('#page').paginator('option', {
                        totalCounts: data['total_count']  // 动态修改总数
                    });
                }
            });
        }
    })


</script>
{/block}
